package com.woniuxy.rms.schedule;

import com.woniuxy.rms.advice.LogPoint;
import com.woniuxy.rms.dao.LogsMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Calendar;

/**
 * Auther: ChenGang  <br/>
 * Date: 2020/3/28 0028:下午 5:26  <br/>
 * Description:日志定期清除
 */
@Component
@Slf4j
@PropertySource("classpath:config/global.properties")//加载配置文件
public class LogSchedule {
    @Value("${logDeleteTime.day}")
    private Integer deleteDay;

    @Autowired
    LogsMapper logsMapper;

    //秒、分、时、日、月、星期
    @Scheduled(cron = "0 0 0 1 1/1 ?")//每月的1日0时0分0秒清理
    @LogPoint("系统清理日志信息")
    public void clearLog(){
        Calendar now = Calendar.getInstance();
        now.add(Calendar.DAY_OF_YEAR,-deleteDay);//deleteDay天前的时间点
        int count = logsMapper.clearLog(now.getTime());
        log.info("系统清理"+count+"条日志");
    }
}